//
//  YCPhotoModel.swift
//  YCCamera
//
//  Created by Billy on 3/7/25.
//
import UIKit
import Photos

let YCMaxImageWidth: CGFloat = 500

class YCPhotoModel: NSObject {
    
    let asset: PHAsset
    
    init(asset: PHAsset) {
        self.asset = asset
        super.init()
    }
    
    // 宽高比
    var whRatio: CGFloat {
        return CGFloat(asset.pixelWidth) / CGFloat(asset.pixelHeight)
    }
    
    // 预览尺寸
    var previewSize: CGSize {
        let scale: CGFloat = UIScreen.main.scale
        if whRatio > 1 {
            let h = min(UIScreen.main.bounds.height, YCMaxImageWidth) * scale
            let w = h * whRatio
            return CGSize(width: w, height: h)
        } else {
            let w = min(UIScreen.main.bounds.width, YCMaxImageWidth) * scale
            let h = w / whRatio
            return CGSize(width: w, height: h)
        }
    }
    
}
